<?php
/**
 *
 * (model)
 */
namespace App\Models\Quality;

use App\Models\Basics\SysCountry;
use App\Models\Basics\SysArea;
use App\Models\Product\ProductSku;
use App\Models\Product\ProductClassify;
use Illuminate\Database\Eloquent\Model;
class QComplaintTotal extends Model
{
    protected $table = 'quality_complaint_total';

    protected $guarded = [];

    protected $casts = [
        'tag' => 'array',
    ];

    public static $_origin = [
        1 => 'Email',
        2 => 'Review',
        3 => 'Feedback',
        4 => '社媒',
        9 => '其他',
        10 =>'退货',
    ];

    public static $_status = [
        0 => '未统计',
        1 => '已统计',
    ];

    const TYPE_RETRUN = 1;
    const TYPE_COMPLAINT = 2;
    public static $_type = [
        self::TYPE_RETRUN => '退货',
        self::TYPE_COMPLAINT => '客诉'
    ];

    public function area(){
        return $this->belongsTo(SysArea::class,'area_id');
    }

    public function country(){
        return $this->belongsTo(SysCountry::class,'country_id');
    }

    public function sku(){
        return $this->belongsTo(ProductSku::class,'psku_id');
    }

    public function classify(){
        return $this->belongsTo(ProductClassify::class,'classify_id');
    }

    //默认基于当前模型名(QComplaint)来决定外键名称：模型名_id
    public function image(){
        return $this->hasOne(QComplaintImage::class,'complaint_id');
    }

//    public static function getData($re){
//        foreach ($re as $row){
//            $temp = [
//                $row->report_date,
//                $row->area->area ?? '',
//                $row->country->country ?? '',
//                self::$_origin[$row->origin],
//                $row->order_no,
//                $row->sku->psku_code ?? '',
//                $row->sku->psku_cn ?? '',
//                $row->classify->title ?? '',
//                $row->seller_sku,
//                $row->content,
//                is_null($row->tag) ? '' : implode(',',QDictTag::getTag($row->tag)),
////                self::$_status[$row->status],
//            ];
//            yield $temp;
//        }
//    }

}
